package com.edu.aspect;
/*
 * @Author:princess
 * @Date 2023/10/31 10 31 20:58
 *
 */

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

import java.util.Date;

public class LogAspect {
    public void before(JoinPoint jt){
        System.out.println("执行了前置通知");
    }

    public void afterRetrun(JoinPoint jt,Object result){
        System.out.println("执行了后置返回通知");
    }

    public void afterThrowing(JoinPoint jt,Throwable throwable){
        System.out.println("执行了后置异常通知");
    }

    public void after(JoinPoint jt){
        System.out.println("执行了后置通知");
    }

    public Object around(ProceedingJoinPoint jt) throws Throwable {
        System.out.println("执行了前置通知");
        long start = System.currentTimeMillis();
        Object result = jt.proceed();
        long end = System.currentTimeMillis();
        System.out.println("时间:"+new Date()+"\t"+jt.getTarget()+"\t"+"方法名："+jt.getSignature().getName()+"\t"+"耗时："+(end-start));
        System.out.println("执行了后置通知");
        return result;
    }
}
